package org.bet.domain;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;

@Document
@CompoundIndexes({
	@CompoundIndex(name = "name_idx", def = "{'genomeId': 1, 'name': 1}, {unique: true}"),
})
public class Assembly extends AbstractIDAssignedObject {
	private static final long serialVersionUID = 863997956744968077L;

	@Indexed
	private String name;
	
	@Indexed
	private String genomeId;
	private String description;	
	private long size;
		
	public Assembly(String name, String genomeId) {
		super(generateId(name, genomeId));
	
		Assert.hasText(name, "name should be not empty");
		Assert.hasText(genomeId, "genomeId should be not empty");
		
		this.name = name;
		this.genomeId = genomeId;		
	}

	protected static String generateId(String name, String genomeId) {
		return genomeId + ":" + name;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getGenomeId() {
		return genomeId;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
